R211021
SBSOPEN, 2021
fjmucho0@gmail.com
4 elementos
5 nodos
import numpy as np
import pandas as pd
Propiedades del material
# areaA = [1000 1000 1000 1000 1000]; % [m^2]
moduE = [2e8, 2e8, 2e8, 2e8]; # [kN/m^2]
inerI = [1, 1, 1, 1]; # [m^4]
Propiedades de la estructura
longL = [2.0, 2.0, 5.0, 7.0]; # [m]
# Cargas Distribuidas: qi, qf son positivo hacia abajo para el ingreso.
# qDist[elemento carga_izq cargas_der; ...];
qDist = np.array([
[2, 4.0, 4.0],
[3, 10.0, 10.0]
]); #[kN/m]
# Cargas Puntual: qPunt positivo hacia abajo,
# momento de fuerza positiva hacia antihorario.
# qPunt[NumeroNodo FuerzaVert MoementoFuerza; ...];
qPunt = np.array([
[1, 20, 0]
]); #[kN/m]
# Restricciones o apoyos.
# apoyos[NumeroNodo Restric_vert Restric_giro; ...]
apoyos = np.array([
[0, 1, 1], # elemento 0
[2, 1, 0], # elemento 2
[3, 1, 0],
[4, 1, 0]
]);
# nn = size(coord, 1);
# ne = size(coord, 1);
NoElem= len(longL);
NoGDL = (NoElem+1)*2;
print(f"Número de elementos: {NoElem}\nNúmero de grados de libertad: {NoGDL}")
Número de elementos: 4 Número de grados de libertad: 10
Matriz de rigidez del elemento
Formulacion Matemática para la Viga: "Viga de Bernoulli" que se define por su módulo de elasticidad $E$, su inercia $I$ y su longitud $L$, a partir de esos datos se obtiente la matriz de rigidez del elemento: $$ \mathbf{k_i} = \dfrac{EI}{L^3} \begin{bmatrix} 12 & 6L & -12 & 6L \\ 6L & 4L^2 & -6L & 2L^2 \\ -12 & -6L & 12 & -6L \\ 6L & 2L^2 & -6L & 4L^2 \end{bmatrix} $$
# Generacion de matris de rigides de los elementos (Ke)
Kelem = np.zeros([4, 4, NoElem]);
for i in range(0,NoElem): # ne
a = 12*moduE[i]*inerI[i]/longL[i]**3;
b = 6*moduE[i]*inerI[i]/longL[i]**2;
c = 4*moduE[i]*inerI[i]/longL[i];
d = 2*moduE[i]*inerI[i]/longL[i];
Kelem[i] = np.array([\
[a, b, -a, b],
[b, c, -b, d],
[-a, -b, a, -b],
[b, d, -b, c]]);
nudoCargado = qDist;
# endfor
# print(nudoCargado)
print(Kelem)
[[[ 3.00000000e+08 3.00000000e+08 -3.00000000e+08 3.00000000e+08] [ 3.00000000e+08 4.00000000e+08 -3.00000000e+08 2.00000000e+08] [-3.00000000e+08 -3.00000000e+08 3.00000000e+08 -3.00000000e+08] [ 3.00000000e+08 2.00000000e+08 -3.00000000e+08 4.00000000e+08]] [[ 3.00000000e+08 3.00000000e+08 -3.00000000e+08 3.00000000e+08] [ 3.00000000e+08 4.00000000e+08 -3.00000000e+08 2.00000000e+08] [-3.00000000e+08 -3.00000000e+08 3.00000000e+08 -3.00000000e+08] [ 3.00000000e+08 2.00000000e+08 -3.00000000e+08 4.00000000e+08]] [[ 1.92000000e+07 4.80000000e+07 -1.92000000e+07 4.80000000e+07] [ 4.80000000e+07 1.60000000e+08 -4.80000000e+07 8.00000000e+07] [-1.92000000e+07 -4.80000000e+07 1.92000000e+07 -4.80000000e+07] [ 4.80000000e+07 8.00000000e+07 -4.80000000e+07 1.60000000e+08]] [[ 6.99708455e+06 2.44897959e+07 -6.99708455e+06 2.44897959e+07] [ 2.44897959e+07 1.14285714e+08 -2.44897959e+07 5.71428571e+07] [-6.99708455e+06 -2.44897959e+07 6.99708455e+06 -2.44897959e+07] [ 2.44897959e+07 5.71428571e+07 -2.44897959e+07 1.14285714e+08]]]
# Generacion de gdl por elemento o para Reigides de cada elemento(Ke)
punt = np.zeros([NoElem,4]);
for i in range(0,NoElem):
for j in range(0, 4):
punt[i,j] = (i*2) + (j);
punt
array([[0., 1., 2., 3.],
[2., 3., 4., 5.],
[4., 5., 6., 7.],
[6., 7., 8., 9.]])
Demo
# Demo.
# kg = np.zeros([9,9]);
# kg[0:4,0:4] += np.ones([4,4])
# kg[2:6,2:6] += np.ones([4,4])*2
# # kg[[4,5,6,7],[4,5,6,7]] += np.ones([4,4])
# kg
Kglobal = np.zeros([NoGDL,NoGDL]);
for i in range(0,NoElem):
posicIni = int(punt[i,0]);
posicFin = int(punt[i,-1])+1;
Kglobal[posicIni:posicFin, posicIni:posicFin] += Kelem[i];
# endfor
del posicIni, posicFin
data = pd.DataFrame(Kglobal)
# print(f"Matriz Global Enzamblada (K).\n{Kglobal.round(2)}");
data
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 300000000.0 | 300000000.0 | -300000000.0 | 300000000.0 | 0.0 | 0.0 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 |
| 1 | 300000000.0 | 400000000.0 | -300000000.0 | 200000000.0 | 0.0 | 0.0 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 |
| 2 | -300000000.0 | -300000000.0 | 600000000.0 | 0.0 | -300000000.0 | 300000000.0 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 |
| 3 | 300000000.0 | 200000000.0 | 0.0 | 800000000.0 | -300000000.0 | 200000000.0 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 |
| 4 | 0.0 | 0.0 | -300000000.0 | -300000000.0 | 319200000.0 | -252000000.0 | -1.920000e+07 | 4.800000e+07 | 0.000000e+00 | 0.000000e+00 |
| 5 | 0.0 | 0.0 | 300000000.0 | 200000000.0 | -252000000.0 | 560000000.0 | -4.800000e+07 | 8.000000e+07 | 0.000000e+00 | 0.000000e+00 |
| 6 | 0.0 | 0.0 | 0.0 | 0.0 | -19200000.0 | -48000000.0 | 2.619708e+07 | -2.351020e+07 | -6.997085e+06 | 2.448980e+07 |
| 7 | 0.0 | 0.0 | 0.0 | 0.0 | 48000000.0 | 80000000.0 | -2.351020e+07 | 2.742857e+08 | -2.448980e+07 | 5.714286e+07 |
| 8 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | -6.997085e+06 | -2.448980e+07 | 6.997085e+06 | -2.448980e+07 |
| 9 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 2.448980e+07 | 5.714286e+07 | -2.448980e+07 | 1.142857e+08 |
cargas distribuidas y puntuales
# Generacion del vector de cargas distribuidas
NoElemCar = np.shape(qDist)[0]; # tamanio de qDist
Fdist = np.zeros([NoGDL,1]);
for i in range(0,NoElemCar):
elem = int(qDist[i,0]);
q1 = qDist[i,1];
q2 = qDist[i,2];
if (q2>q1):
f1 = -q1*longL[elem]/2 - 3/20*(q2-q1)*longL[elem];
m1 = -q1*longL[elem]**2/12 - (q2-q1)*longL[elem]**2/30;
f2 = -q1*longL[elem]/2 - 7/20*(q2-q1)*longL[elem];
m2 = +q1*longL[elem]**2/12 + (q2-q1)*longL[elem]**2/20;
elif (q2<q1):
f1 = -q2*longL[elem]/2 - 7/20*(q1-q2)*longL[elem];
m1 = -q2*longL[elem]**2/12 - (q1-q2)*longL[elem]**2/20;
f2 = -q2*longL[elem]/2 - 3/20*(q1-q2)*longL[elem];
m2 = +q2*longL[elem]**2/12 + (q1-q2)*longL[elem]**2/30;
elif (q2==q1):
f1 = -q1*longL[elem]/2;
m1 = -q1*longL[elem]**2/12;
f2 = -q1*longL[elem]/2;
m2 = +q1*longL[elem]**2/12;
# grados de libertad de destino
gdl1 = int(punt[elem,0]);
gdl2 = int(punt[elem,1]);
gdl3 = int(punt[elem,2]);
gdl4 = int(punt[elem,3]);
Fdist[gdl1,0] += f1;
Fdist[gdl2,0] += m1;
Fdist[gdl3,0] += f2;
Fdist[gdl4,0] += m2;
# endfor
# Generacion del vector de cargas puntuales
NoCarPunt = np.shape(qPunt)[0];
Fpunt = np.zeros([NoGDL,1]);
for i in range(0,NoCarPunt):
gdlF = qPunt[i,0]*2-0;
puntual = -qPunt[i,1]; # carga puntual
gdlM = qPunt[i,0]*2;
momFuerza = qPunt[i,2]; # momento
Fpunt[gdlF,0] += puntual;
Fpunt[gdlM,0] += momFuerza;
# endfor
F = Fdist+Fpunt;
print(f"Matriz de Fuerzas global (F).\n{F}");
Matriz de Fuerzas global (F). [[ 0. ] [ 0. ] [-20. ] [ 0. ] [-10. ] [ -8.33333333] [-45. ] [-32.5 ] [-35. ] [ 40.83333333]]
# bucle de restricciones
NoApoyosRest = np.shape(apoyos)[0];
GDLrestringidos = np.zeros([NoApoyosRest+1]);
contador = 0;
for i in range(0,NoApoyosRest):
NudoRest = int(apoyos[i,0]); # columna 1
if apoyos[i,1]==1: # columna 2
GDLrestringidos[contador] = NudoRest*2;
contador = contador + 1;
if apoyos[i,2]==1: # columna 3
GDLrestringidos[contador] = NudoRest+1;
contador = contador + 1;
# endfor
del contador
GDLrestringidos
array([0., 1., 4., 6., 8.])
Eliminar filas y columnas de la matriz global, segun nudo restringido
# # Demo.
kg = np.array([
[1,2,3,4],
[5,6,7,8],
[9,10,11,12],
[97,15,41,2],
])
# kg=np.delete(kg, [0,2],0)
kg=np.delete(kg, np.s_[0,3], 1)
kg
array([[ 2, 3],
[ 6, 7],
[10, 11],
[15, 41]])
# Reduccion de los GDL restricciones del sistema lineal
Kred = Kglobal;
Fred = F;
gdlKres = []
for i in range(len(GDLrestringidos)):
gdlKres.append(int(GDLrestringidos[i])) # esto es un recurso para tener en formato lista.s
Kred=np.delete(Kred, gdlKres, 0); # eliminamos filas
Kred=np.delete(Kred, np.s_[gdlKres], 1) # eliminamos columnas
# Fred[GDLrestringidos,:] = [];
Fred=np.delete(Fred, gdlKres, 0)
data = pd.DataFrame(Kred)
print(f"Matriz Global reducida (Kr).\n{data}");
print(f"Matriz de fuerzas reducida (Fred).\n{Fred}");
# se encuentran los desplazamientos del sistema
Ured = np.linalg.inv(Kred)@Fred;
Ured = np.linalg.inv(Kred)@Fred;
# Ured
Matriz Global reducida (Kr).
0 1 2 3 4
0 600000000.0 0.0 300000000.0 0.000000e+00 0.000000e+00
1 0.0 800000000.0 200000000.0 0.000000e+00 0.000000e+00
2 300000000.0 200000000.0 560000000.0 8.000000e+07 0.000000e+00
3 0.0 0.0 80000000.0 2.742857e+08 5.714286e+07
4 0.0 0.0 0.0 5.714286e+07 1.142857e+08
Matriz de fuerzas reducida (Fred).
[[-20. ]
[ 0. ]
[ -8.33333333]
[-32.5 ]
[ 40.83333333]]
Matriz de desplazamientos (U) y Matriz de reacciones (F)
# Calculo de U con los GDL restringidos
puntU=np.arange(1,NoGDL+1,1).T;
puntU=np.delete(puntU, gdlKres, 0)
U = np.zeros([NoGDL,1]);
NoGDLlibres = np.shape(Ured)[0]; # numero de gdl libres
for i in range(0,NoGDLlibres):
destino = puntU[i]-1;
U[destino,0] = Ured[i,0];
print(f"Matriz de desplazamientos (U).\n{U.round(4)}");
# Reacciones
Reacc = Kglobal@U-F;
print(f"Matriz de reacciones en los Nudos(F).\n{Reacc.round(4)}");
Matriz de desplazamientos (U). [[ 0.] [ 0.] [-0.] [-0.] [ 0.] [ 0.] [ 0.] [-0.] [ 0.] [ 0.]] Matriz de reacciones en los Nudos(F). [[14.2436] [15.6581] [-0. ] [ 0. ] [ 7.2509] [ 0. ] [59.393 ] [ 0. ] [29.1126] [ 0. ]]
import matplotlib.pyplot as plt
calculo de cordenadas de cada tramo.
coords[nidoId, x, y]
coords = np.zeros([NoElem,3]);
coords[:,0] =np.arange(1,NoElem+1,1).T;
# para el tramo/elemento 1:
coords[0,2] = longL[0];
# calculo de coordenadas del tramo/elemento 2 en adenlante
for i in range(1,NoElem):
coords[i,1] = coords[i-1,2];
coords[i,2] = coords[i,1] + longL[i];
coords
array([[ 1., 0., 2.],
[ 2., 2., 4.],
[ 3., 4., 9.],
[ 4., 9., 16.]])
# Calculo de matriz completa de cargas distribuidas
q1Yq2 = np.zeros([NoElem, 2]);
for i in range(0,NoElemCar):
filaCargada = int(qDist[i,0]);
q1Yq2[filaCargada,0] = qDist[i,1];
q1Yq2[filaCargada,1] = qDist[i,2];
q1Yq2
array([[ 0., 0.],
[ 0., 0.],
[ 4., 4.],
[10., 10.]])
Sistema de ecuaciones... $Ax=B$
$A = \frac{q_2-q_1}{x_2-x_1} \tag{1}$
$B = q_1-Ax_1 \tag{2}$
Sistema de ecuaciones en su formato matricial. $x=A^{-1}B$ $$ \begin{bmatrix} C1 \\ C2 \\ C3 \\ C4 \end{bmatrix} = \begin{bmatrix} \frac{x_{1}^3}{6} & \frac{x_{1}^2}{2} & x_{1} & 1 \\ \frac{x_{1}^2}{2} & x_{1} & 1 & 0 \\ \frac{x_{2}^3}{6} & \frac{x_{2}^2}{2} & x_{2} & 1 \\ \frac{x_{2}^2}{2} & x_{2} & 1 & 0 \end{bmatrix}^{-1} \begin{bmatrix} EI*U_{1} + A*\frac{x_{1}^5}{120} + B*\frac{x_{1}^4}{24} \\ EI*U_{2} + A*\frac{x_{1}^4}{24} + B*\frac{x_{1}^3}{6} \\ EI*U_{3} + A*\frac{x_{2}^5}{120} + B*\frac{x_{2}^4}{24} \\ EI*U_{4} + A*\frac{x_{2}^4}{24} + B*\frac{x_{2}^3}{6} \end{bmatrix} \tag{3}$$
# Calculo de los coeficientes C1, C2, C3, C4 para Graficar V y M
# Calculo de A B C1, C2, C3, C4
constantes = np.zeros([NoElem, 6]);
for i in range(0,NoElem):
x1 = coords[i,1];
x2 = coords[i,2];
q1 = q1Yq2[i,0];
q2 = q1Yq2[i,1];
EI = moduE[i]*inerI[i];
u1 = U[int(punt[i,0]),0];
u2 = U[int(punt[i,1]),0];
u3 = U[int(punt[i,2]),0];
u4 = U[int(punt[i,3]),0];
# Calculo A y B
A = (q2-q1)/(x2-x1);
B = q1-A*x1;
# Caclulo de matrices cuadradas del Sist.Ec.
matXX = [
[x1**3/6, x1**2/2, x1, 1],
[x1**2/2, x1, 1, 0],
[x2**3/6, x2**2/2, x2, 1],
[x2**2/2, x2, 1, 0]];
vecUAB = [
[EI*u1 + A*x1**5/120 + B*x1**4/24],
[EI*u2 + A*x1**4/24 + B*x1**3/6],
[EI*u3 + A*x2**5/120 + B*x2**4/24],
[EI*u4 + A*x2**4/24 + B*x2**3/6]];
Cs = np.linalg.inv(matXX)@vecUAB;
constantes[i,0] = A;
constantes[i,1] = B;
constantes[i,2] = Cs[0,0];
constantes[i,3] = Cs[1,0];
constantes[i,4] = Cs[2,0];
constantes[i,5] = Cs[3,0];
data = pd.DataFrame(constantes.round(3))
data
| 0 | 1 | 2 | 3 | 4 | 5 | |
|---|---|---|---|---|---|---|
| 0 | 0.0 | 0.0 | 14.244 | -15.658 | 0.000 | 0.000 |
| 1 | 0.0 | 0.0 | -5.756 | 24.342 | -40.000 | 26.667 |
| 2 | 0.0 | 4.0 | 17.494 | -36.662 | 60.674 | -93.343 |
| 3 | 0.0 | 10.0 | 130.887 | -814.198 | 3195.088 | -8949.837 |
# # Demo.
# # data = np.linspace(1,1,5)
#
# data = [1,2,3,5,7]
# data.extend([1,2,4]) # comple la funcion de concatenar
# data
# graficacion del diagrama de moemento y cortantes
xTot, VTot, MTot = [], [], [];
Tags = np.zeros([NoElem,6]) # [4,6], 4 filas 6 columnas
for i in range(0,NoElem):
xi = coords[i,1];
xf = coords[i,2];
A = constantes[i,0];
B = constantes[i,1];
C1 = constantes[i,2];
C2 = constantes[i,3];
C3 = constantes[i,4];
C4 = constantes[i,5];
xTramo = np.linspace(xi,xf,21); # tramos o diviciones
VTramo = -(A*xTramo**2)/2 - B*xTramo + C1; # cortante de tramo
MTramo = -(A*xTramo**3)/6 - (B*xTramo**2)/2 + C1*xTramo + C2;
Tags[i,0] = xi;
Tags[i,1] = xf;
Tags[i,2] = VTramo[0];
Tags[i,3] = VTramo[20];
Tags[i,4] = MTramo[0];
Tags[i,5] = MTramo[20];
# TagsProm(i,1)=(Tags(i,5)+Tags(i,6))/2; % promedio
# concatenamos los puntos en los vectores totales
xTot.extend(xTramo);
VTot.extend(VTramo);
MTot.extend(MTramo);
numLineas = np.size([VTot,2]);
yCero = np.zeros([1,numLineas]);
c:\users\jimenez\appdata\local\programs\python\python38\lib\site-packages\numpy\core\fromnumeric.py:3208: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. return asarray(a).size
# plt.style.available?
plt.style.use('seaborn') #bmh
fig, (ax1,ax2,ax3) = plt.subplots(figsize=(16.5, 10), nrows=3,ncols=1, sharex=True)
ax1.plot([min(xTot),max(xTot)],[0,0], color='#000111', lw=4)
ax2.plot([min(xTot),max(xTot)],[0,0], color='#ccc', lw=4)
ax2.plot(xTot, VTot, lw=0.5, color='#41a4ff') # alpha=0.7
ax3.plot([min(xTot),max(xTot)],[0,0], color='#ccc', lw=4)
ax3.plot(xTot, MTot, lw=0.5, color='#41a4ff') # alpha=0.7
plt.show()
fig, (ax1, ax2, ax3)=plt.subplots(nrows=3, ncols=1, sharex=True, figsize=(16,12))
xIni = xTot[0];
xFin = xTot[-1];
# Calculamos las coordenadas de los nudos
coordNudos = np.zeros(NoElem+1);
coordNudos[0] = 0;
for i in range(0,NoElem):
coordNudos[i+1]=coordNudos[i]+longL[i];
h=xFin/20;
base = h;
ax1.fill_between([xIni, xFin],[-h, -h], facecolor=(1, 1, 0.5), lw=1)
ax1.set_ylim([-4*h, 8*h]);
# set(gca, "Visible","off")
# ----- dibujo de restricciones -----
for i in range(0,NoApoyosRest):
nudoApoyayo = apoyos[i,0]
coordApodo = coordNudos[nudoApoyayo];
restVert = apoyos[i,1];
restMom = apoyos[i,2];
if (restVert==1 and restMom==1):
ax1.plot([coordApodo, coordApodo],[2*h, -2*h], color='#04101998', lw=2)
elif (restVert==1 and restMom==0):
ax1.plot([coordApodo, coordApodo-base/2],[-h, -2.5*h], color='#04101998', lw=2)
ax1.plot([coordApodo,coordApodo+base/2],[-h, -2.5*h], color="#04101998", lw=2)
ax1.plot([coordApodo-base/2, coordApodo+base/2],[-2.5*h, -2.5*h], color="#04101998", lw=4)
else:
pass
# ----- ploteamos la carga distribuida -----
temp = qDist;
temp=np.delete(temp, np.s_[0,1], 1) # temp(:,1) = [];
qmax = max(max(temp));
for i in range(0,NoElemCar):
elementoCargado = int(qDist[i,0]);
xInicial = coords[elementoCargado,1];
xFinal = coords[elementoCargado,2];
qInicial = qDist[i,1]/qmax*6*h; # altura normalizada
qFinal = qDist[i,2]/qmax*6*h;
ax1.fill_between([xInicial, xFinal], [qInicial, qFinal], facecolor=(0.2, 0.7, 0.7), lw=1)
ax1.text(xInicial, qInicial+h, str(qDist[i,1])) # texto
ax1.text(xFinal, qFinal+h, str(qDist[i,2])) # texto
# ----- ploteando carga puntuales para normalizar las cargas la q_maxima -----
for i in range(0,NoCarPunt):
nudoCargado = qPunt[i,0];
coordNudoCargado = coordNudos[nudoCargado];
cargaVertical = qPunt[i,1];
cargaMomento = qPunt[i,2];
if (cargaVertical!=0):
ax1.plot([coordNudoCargado, coordNudoCargado],[6*h, 0], color='k', lw=2)
ax1.plot([coordNudoCargado-base/4, coordNudoCargado],[h, 0], color='k', lw=2)
ax1.plot([coordNudoCargado+base/4, coordNudoCargado],[h, 0], color='k', lw=2)
ax1.text(coordNudoCargado, 3.5+h, str(cargaVertical)) # texto
elif (cargaMomento!=0):
pass # graficar...
# ax1.plot([coordNudoCargado, coordNudoCargado],[6*h, 0], lw=2)
# ax1.plot([coordNudoCargado-base/4, coordNudoCargado],[h, 0], lw=2)
# ax1.plot([coordNudoCargado+base/4, coordNudoCargado],[h, 0], lw=2)
# ax1.text(coordNudoCargado, 7+h, str(cargaVertical));
else:
pass
ax2.plot(xTot,VTot, label="M1", linewidth=1.0, color="green")
ax2.fill_between(xTot, VTot, alpha=0.3, color="green")
ax2.set_ylabel("Shear Force (kN)", fontsize=9)
ax2.invert_yaxis()
Temp = (Tags[:,5:6]);
Vmax = max(max(abs(Temp)));
for i in range(0, NoElem): # nn
xini = Tags[i,0]; # coordIni
xfin = Tags[i,1]; # coordFin
Vini = round(Tags[i,2],1); # cortanteIni, con 2 digitos
Vfin = round(Tags[i,3],1);
if Vini >= 0:
ax2.text(xini, Vini+0.1*Vmax, str(Vini));
ax2.text(xfin, Vfin+0.1*Vmax, str(Vfin));
else:
ax2.text(xini, Vini-0.1*Vmax, str(Vini))
ax2.text(xfin, Vfin-0.1*Vmax, str(Vfin))
ax3.plot(xTot,MTot, label="M1", linewidth=1.0, color="red")
ax3.fill_between(xTot, MTot, alpha=0.3, color="red")
ax3.set_ylabel("bending Momenet (kNm)", fontsize=9)
ax3.set_xlabel("distance (m)")
ax3.invert_yaxis()
Temp = Tags[:,5:6];
Mmax = max(max(np.abs(Temp)));
for i in range(0, NoElem):
xini = Tags[i,0];
xfin = Tags[i,1];
Mini = round(Tags[i,4], 2);
Mfin = round(Tags[i,5], 2);
if Mini>=0: ax3.text(xini, Mini+0.07*Mmax, str(Mini));
else: ax3.text(xini, Mini-0.07*Mmax, str(Mini))
if Mfin>=0: ax3.text(xfin, Mfin+0.07*Mmax, str(Mfin));
else: ax3.text(xfin, Mfin-0.07*Mmax, str(Mfin))
plt.show()
Plotly. referecne: Plotly docs
to install, type the following into your terminal:
conda install -c plotly
pip install plotly
import plotly as ply
import plotly.graph_objs as pgo
ply.offline.init_notebook_mode(connected=False) # Setup offline plotting
span = max(xTot); # Span of beam - distancia total de la viga.
# Define the layout object
layout = pgo.Layout(
title = {
"text": 'Shear Force Diagram',
'y': 0.85,
'x': 0.5,
'xanchor': 'center',
'yanchor': 'top'
},
yaxis = dict(title='Shear Force (kN)'),
xaxis = dict(
title='Distance (m)',
range = [-1, span+1]
),
showlegend=False,
)
line = pgo.Scatter(
x=xTot,
y=VTot,
mode = 'lines',
name = 'Shear Force ',
fill='tonexty',
line_color = 'green',
fillcolor = 'rgba(0, 255, 0, 0.1)',
)
axis = pgo.Scatter(
x = [0, span],
y = [0, 0],
mode = 'lines',
line_color = 'black',
)
# generate and view the figure
fig = pgo.Figure(data=[line, axis], layout=layout)
ply.offline.iplot(fig)
# Define the layout object
layout = pgo.Layout(
title = {
"text": 'bending Momenet Diagram',
'y': 0.85,
'x': 0.5,
'xanchor': 'center',
'yanchor': 'top'
},
yaxis = dict(
title='bending Momenet (kNm)',
autorange = 'reversed'
),
xaxis = dict(
title='Distance (m)',
range = [-1, span+1]
),
showlegend=False,
)
line = pgo.Scatter(
x=xTot,
y=MTot,
mode = 'lines',
name = 'Bending Moment',
fill='tonexty',
line_color = 'red',
fillcolor = 'rgba(255, 0, 0, 0.1)',
)
axis = pgo.Scatter(
x = [0, span],
y = [0, 0],
mode = 'lines',
line_color = 'black',
)
# generate and view the figure
fig = pgo.Figure(data=[line, axis], layout=layout)
ply.offline.iplot(fig)
# # 5.0. Deflexion calculation.
# Numerical Solution of the Differential Equation of the Deflection Curve.
# layout = pgo.Layout(
# title={
# 'text':"Deflection",
# 'y':0.85,
# 'x':0.5,
# 'xanchor': 'center',
# 'yanchor': 'top'
# },
# titlefont = dict(size=15),
# yaxis = dict(
# title='Deflection'
# ),
# xaxis = dict(
# title = 'Distance (m)',
# range=[-1, span+1]
# ),
# showlegend = False,
# )
# # Define the deflection shape trace
# line = pgo.Scatter(
# x=xTot,
# y = Deflection,
# mode ='lines',
# name='Deflection',
# line_color='orange',
# fill='tonexty',
# fillcolor = 'rgba(255,255,0, 0.1)'
# )
# # Define a horizontal line to represent the structure
# axis = pgo.Scatter(
# x = [0, span],
# y = [0,0],
# mode='lines',
# line_color='black'
# )
# # Generate and view the figure
# fig = pgo.Figure(data = [line,axis], layout=layout)
# ply.offline.iplot(fig)